﻿using System;
using System.Collections.Generic;
using System.Text;
using TTClassLibrary;
using TTServer.Messages;
using libCommonClass;
using TTServer.Controller;
using libInterface;
using libUtilities;
using System.Drawing;
using bmttPPTController.TTServer;
using TTServer.Objects;

namespace TTServer.MessageProcessor
{
    public class PPTSlideShowDataRequestMessageProcessor : IMessageProcessor
    {
        public bool Process(libCommonClass.TTMessage message, libInterface.IClientInfoProvider clientInfoProvider)
        {
            if (message is PPTSlideShowDataRequestMessage)
            {
                if (!(clientInfoProvider.Authority == AuthorityConstant.ADMIN
                    || clientInfoProvider.Authority == AuthorityConstant.KEY_MEMBER))
                {
                    return true;
                }

                PPTController pptCtrl = PPTController.Instance;

                if (!pptCtrl.checkPPTApplicationRun())
                {
                    NotifyMessage nm = new NotifyMessage("PPT Controller not run");

                    clientInfoProvider.AddToMessageQueue(nm);

                    return true;
                }

                SendSlideShowDataResponseMessage(clientInfoProvider);

                return true;
            }

            return false;
        }

        private void SendSlideShowDataResponseMessage(IClientInfoProvider clientInfoProvider)
        {
            PPTController pptCtrl = PPTController.Instance;

            List<CSlideData> list = pptCtrl.GetAllSlideNumberAndSlideTitle();

            if (list != null)
            {
                if (list.Count > 0)
                {
                    CSlideData[] temp = list.ToArray();

                    SlideshowDataResponseMessage t1_msg = new SlideshowDataResponseMessage(clientInfoProvider.TemporaryKey, temp);

                    clientInfoProvider.AddToMessageQueue(t1_msg);
                }
                else if (list.Count == 0)
                {
                    NotifyMessage t2_msg = new NotifyMessage("Cannot obtain slide data.");

                    clientInfoProvider.AddToMessageQueue(t2_msg);
                }
            }
            else
            {
                NotifyMessage t3_msg = new NotifyMessage("Cannot obtain slide data.");

                clientInfoProvider.AddToMessageQueue(t3_msg);
            }
        }
    }
}
